package com.brainsz.android.taskreminder;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ReminderListActivity extends ListActivity {
    /** Called when the activity is first created. */
	
	private static final int ACTIVITY_CREATE= 0;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reminder_list);
        
        final String[] items;
        items = new String[] { "Foo", "Bar", "Fizz", "Bin" };
        
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
        setListAdapter(adapter);
        registerForContextMenu(getListView());
    }
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    	super.onListItemClick(l, v, position, id);
    	Intent i = new Intent(this, ReminderEditActivity.class);
    	i.putExtra("RowId", id);
    	startActivity(i);
    	
    }
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    	super.onCreateContextMenu(menu, v, menuInfo);
    	MenuInflater mi = getMenuInflater();
    	mi.inflate(R.menu.list_menu_item_longpress, menu);
    	
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
    	super.onCreateOptionsMenu(menu);
    	MenuInflater mi = getMenuInflater();
    	mi.inflate(R.menu.list_menu, menu);
    	return true;
    }
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item)
    {
    	switch (item.getItemId()) {
    		case R.id.menu_insert:
    			createReminder();
    			return true;
    	}
    	return super.onMenuItemSelected(featureId, item);
    }

	private void createReminder() {
		Intent i = new Intent(this, ReminderEditActivity.class);
		startActivityForResult(i, ACTIVITY_CREATE);
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent intent)
	{
		super.onActivityResult(requestCode, resultCode, intent);
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item)
	{
		switch (item.getItemId()) {
		case R.id.menu_delete:
			//delete task
			return true;
		}
		return super.onContextItemSelected(item);
	}
	
    
    
    
    
    
    
    
    
}